home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / PowerFantasm™ 4.19a / PowerFantasm™ / F4_EXAMPLES / PPC_Graphics_demo / PPC_graph_demo.s < prev   
Text File  |  1997-02-10  |  6KB  |  226 lines

  1. *******************************
  2. **Fantasm V4 PowerPC demo #1
  3. **A PowerPC assembly language example program just for fun.
  4. **Opens a window and runs various graphical tests
  5. **Runs in any colour mode.
  6. **File:PPC_graph_demo.s
  7. **Date: 3rd Dec.95
  8. **©Lightsoft 1995.
  9.  
  10. **Normal Mac init stuff
  11.  
  12. param1:    reg    r3        *Set up the names of the regs used for parameter passing
  13. param2:    reg    r4
  14. param3: reg    r5
  15. param4:    reg    r6
  16. bss:    reg    r30        *The register we use for global data
  17. **Note that if calling system calls, r31 must remain intact, so we simply don't use it.
  18.  
  19. ppc_graph_demo:
  20.         
  21.     ENTRY            *Prog starts here    
  22.     start_up        *save all the regs and set up r30 for global
  23.     la    r3,qd(`bss)    *get the address of the QD array into r3
  24.     addic    r3,r3,206-4
  25.     Xcall    InitGraf    *Init managers
  26.     Xcall    InitFonts
  27.     Xcall    InitWindows
  28.     Xcall    InitMenus
  29.     Xcall    TEInit
  30.     li    `param1,0        
  31.     Xcall    InitDialogs
  32.     Xcall    InitCursor    *Note, we could have called the library function init_mac instead of the previous few lines
  33.     
  34. **Open our window and copy its viewrect.
  35.     bl    graph_demo_init    *initialise and open a window and get its viewrect into viewrect_1(bss)
  36. **now the drawing
  37. **lets start with some nice horizontal lines
  38. **First lets set the foreground colour to white
  39.     lwz    `param1,white(rtoc)
  40.     Xcall    RGBForeColor    *That should do it
  41. **now a simple horiz test line - draw r22 white lines
  42.     la    r3,viewrect_1(`bss)    *top,left,bott,right
  43.     lhz    r20,2(r3)    *left of window
  44.     lhz    r21,6(r3)    *right of window
  45.     lhz    r22,4(r3)    *bottom
  46.  
  47. **use MoveTo and LineTo to draw the line
  48. line_loop:
  49.     bl    draw_line    *draw a line
  50.     subic.    r22,r22,1    *up 1 line
  51.     bne-    line_loop    *and if line y isn't zero draw another line.
  52.     
  53. **now we'll do the same, but change the colours dynamically this time and 
  54. **fill the window 50 times
  55.     li    r26,50        *do it all 50 times
  56. outer_loop:
  57. **reset the x and y's
  58.     la    r3,viewrect_1(`bss)    *top,left,bott,right
  59.     lhz    r20,2(r3)    *left of window
  60.     lhz    r21,6(r3)    *right of window
  61.     lhz    r22,4(r3)    *bottom
  62.  
  63. **Draw line and alter the components of the colour
  64. line_loop_2:
  65.     bl    draw_line    *draw this line
  66.     lwz    r23,white1(rtoc)    *r23 points to our colour that we are altering
  67.  
  68.     lhz    r24,(r23)    *get the red value
  69.     subic    r24,r24,64    *subtract 64 from the red
  70.     sth    r24,(r23)    *save the new colour back in memory
  71.  
  72.     lhz    r24,2(r23)    *get the green value
  73.     subic    r24,r24,32    *subtract 32 from the green
  74.     sth    r24,2(r23)    *save the new colour back in memory
  75.  
  76.     lhz    r24,4(r23)    *get the blue value
  77.     subic    r24,r24,128    *subtract 128 from the blue
  78.     sth    r24,4(r23)    *save the new colour back in memory
  79.     
  80.     lwz    `param1,white1(rtoc)
  81.     Xcall    RGBForeColor    *Set new forground colour to white1
  82.  
  83.     subic.    r22,r22,1    *up 1 line
  84.     bne    line_loop_2    *and if not top of window (line=0) draw next line in new colour.
  85.     
  86.     subic.    r26,r26,1    *do it all r26 times
  87.     bne    outer_loop
  88.  
  89.  
  90.     bl    clear_window    *clear the window out by scrolling
  91.  
  92. **now lets draw a circles
  93.     li    r28,3        *do the zoomy circles 3 times
  94. rgb_zooms:
  95.     lwz    `param1,red(rtoc)
  96.     Xcall    RGBForeColor    *Set new forground colour
  97.     bl    draw_circles    *draw a zoomy circle in red.
  98.  
  99.     lwz    `param1,green(rtoc)
  100.     Xcall    RGBForeColor    *Set new forground colour
  101.     bl    draw_circles    *draw a zoomy circle in green
  102.  
  103.     lwz    `param1,blue(rtoc)
  104.     Xcall    RGBForeColor    *Set new forground colour
  105.     bl    draw_circles    *draw a zoomy circle in blue
  106.     subic.    r28,r28,1
  107.     bne    rgb_zooms
  108.     tidy_up            *restore all the regs back to how they were before this prog started.
  109.     blr            *bye bye - end of program.
  110.  
  111.  
  112. *****************
  113. **Drawing subroutine follow
  114. draw_circles:
  115.     mflr    r29        *save return addr.
  116. **First reduce our viewrect_2 down to a small size
  117.     la    r20,viewrect_1(`bss)    *copy this rect
  118.     la    r22,viewrect_2(`bss)    *to this rect whilst making it smaller
  119.     lhz    r21,(r20)
  120.     addic.    r21,r21,100
  121.     sth    r21,(r22)    *top+100
  122.     
  123.     lhz    r21,2(r20)
  124.     addic.    r21,r21,100
  125.     sth    r21,2(r22)    *left+100
  126.  
  127.     lhz    r21,4(r20)
  128.     subic.    r21,r21,100
  129.     sth    r21,4(r22)    *bottom-100
  130.  
  131.     lhz    r21,6(r20)
  132.     subic.    r21,r21,100
  133.     sth    r21,6(r22)    *right-100
  134.  
  135.     li    r26,100        *loop count
  136. **Now drow r26 circles, each slightly larger than the last    
  137. circles:
  138.     la    `param1,viewrect_2(`bss)    *top,left,bott,right    
  139.     Xcall    PaintOval            *simple?
  140.  
  141.     la    r20,viewrect_2(`bss)    
  142.     lhz    r21,(r20)
  143.     subic.    r21,r21,2
  144.     sth    r21,(r20)    *top-2
  145.     
  146.     lhz    r21,2(r20)
  147.     subic.    r21,r21,2
  148.     sth    r21,2(r20)    *left-2
  149.  
  150.     lhz    r21,4(r20)
  151.     addic.    r21,r21,2
  152.     sth    r21,4(r20)    *bottom+2
  153.  
  154.     lhz    r21,6(r20)
  155.     addic.    r21,r21,2
  156.     sth    r21,6(r20)    *right+2
  157.  
  158.     subic.    r26,r26,1
  159.     bne    circles
  160.     mtlr    r29
  161.     blr
  162.  
  163. *************************************************
  164. **Draws a horizontal line in the forground colour.
  165. **Needs start x in r20, end x in r21 and y in r22
  166. draw_line:
  167.     mflr    r29
  168.     mr    `param1,r20
  169.     mr    `param2,r22
  170.     Xcall    MoveTo
  171.     mr    `param1,r21
  172.     mr    `param2,r22
  173.     Xcall    LineTo
  174.     mtlr    r29
  175.     blr                *easy innit?
  176. ************************************************************************************
  177. **Clears our window by first scrolling diagonally, and then virtically (virtically?).
  178. clear_window:
  179.     mflr    r29        *this is a subroutine, so save return address.
  180. **First lets set the foreground colour to white
  181.     lwz    `param1,white(rtoc)
  182.     Xcall    RGBForeColor    *That should do it
  183.  
  184. *extern pascal void ScrollRect(const Rect *r, short dh, short dv, RgnHandle updateRgn)
  185. **Get height/2 in r22
  186.     la    r20,viewrect_1(`bss)
  187.     lhz    r22,4(r20)    *bottom for use as a loop counter
  188.  
  189. **Scroll diagonally    
  190. scroll_diag_loop:
  191.     la    `param1,viewrect_1(`bss)    *top,left,bott,right    
  192.     li    `param2,1    *dh = delta horizontal = 1 pixel
  193.     li    `param3,1    *dv = delta vertical = 1 pixel = diagonal scroll.
  194.     li    `param4,0    *updatergn
  195.     Xcall    ScrollRect    *scroll by 1 pixels
  196.     subic.    r22,r22,1    *Decrement loop count
  197.     bne    scroll_diag_loop    *and branch if not zero to scroll again
  198.  
  199.     la    r20,viewrect_1(`bss)
  200.     lhz    r22,4(r20)    *bottom for use as loop counter
  201. **Scroll down    
  202. scroll_down_loop:
  203.     la    `param1,viewrect_1(`bss)    *top,left,bott,right    
  204.     li    `param2,0    *dh
  205.     li    `param3,1    *dv
  206.     li    `param4,0    *updatergn
  207.     Xcall    ScrollRect    *scroll by 1 pixel
  208.     subic.    r22,r22,1    *Decrement loop count
  209.     bne    scroll_down_loop    *and branch if not zero to scroll again
  210.  
  211.     mtlr    r29        *get return address
  212.     blr
  213. *********************************************************
  214. **Predefined Data that goes in the data section
  215. **Our colours defined as red,green,blue strengths.
  216. white:    dc.h    0xffff,0xffff,0xffff
  217. white1:    dc.h    0xffff,0xffff,0xffff
  218. red:    dc.h    0xffff,0,0
  219. green:    dc.h    0,0xffff,0
  220. blue:    dc.h    0,0,0xffff
  221. ****
  222. *********************************************************
  223. **The declarations.
  224.     global    ppc_graph_demo
  225.     extern    graph_demo_init    *External initialisation subroutine in graph_demo_init.s
  226.